<template>
	<view class="category-dish">
		<view class="left-category">
			<view>
				<view :class="['category-item', currentCategoryId == item.id ? 'category-select' : '']"
					@click="currentCategoryId = item.id" v-for="(item, index) in category_list" :key="index">{{
						item.categoryName }}
				</view>
			</view>
		</view>
		<view class="right-dish">
			<view class="dish">
				<view class="dish-title">菜品列表</view>
				<view v-for="dish in dishList" :key="dish.id" class="dish-card">
					<view class="dish-logo">
						<image mode="aspectFit" :src="dish.image"></image>
					</view>
					<view class="dish-info">
						<view class="dish-name">{{dish.dishName}}</view>
						<view class="dish-desc">{{dish.description}}</view>
						<view class="dish-sale">销量-好评率</view>
						<view class="dish-new-price">折扣</view>
						<view class="dish-add-box">
							<view class="dish-price">{{dish.price}}</view>
							<view v-if="true" class="dish-choose" @click="choose_specification(dish)">选规格</view>
							<view v-else class="dish-add">+</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<choose-dish :show="choose_show" @close="choose_show=false" :dish='dish'></choose-dish>
	</view>
</template>

<script>
	import {dish_list} from '@/api/shop.js'
	export default {
		name: "category-dish",
		props:{
			category_list:{
				type:Array,
				default:()=>[]
			}
		},
		watch:{
			category_list:{
				deep:true,
				immediate:true,
				handler(val){
					if(val[0]){
						this.currentCategoryId = val[0].id
					}
				}
			},
			currentCategoryId(newVal,oldVal){
				console.log(newVal)
				dish_list(this.currentCategoryId).then(res=>{
					console.log(res)
					this.dishList = res
	
				})
			}
		},
		data() {
			return {
				choose_show: false,
				currentCategoryId: 0,
				dishList:[],
				dish:{},
			}
		},
		mounted(){
			
		},
		methods:{
			choose_specification(dish){
				this.choose_show = true
				this.dish = dish
				this.dish.shopId = 1
			}
		}
	}
</script>

<style scoped>
	.category-dish {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: flex-start;
	}

	.left-category {
		width: 20%;
		height: 100%;
	}

	.right-dish {
		width: 80%;
		height: 100%;
	}

	.category-item {
		height: 100upx;
		line-height: 100upx;
		text-align: center;
		background-color: #eee;
	}

	.category-select {
		background-color: #ffffff;
		border-radius: 0;
	}

	/* 下一个兄弟节点 */
	.category-select+.category-item {
		border-top-left-radius: 0;
		border-top-right-radius: 10upx;
		border-bottom-left-radius: 0;
		border-bottom-right-radius: 0;
	}

	.dish {
		display: flex;
		flex-direction: column;
		align-items: flex-start
	}

	.dish-card {
		width: 95%;
		margin: 10upx auto;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: flex-start;
		background-color: #eee;
	}

	.dish-title {
		width: 95%;
		margin: 20upx auto;
	}

	.dish-logo {
		width: 40%;
		height: 200upx;
	}
	.dish-logo>image{
		width: 200upx;
		height: 200upx;
	}

	.dish-info {
		width: 60%;
	}

	.dish-add-box {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.dish-add {
		width: 50upx;
		height: 50upx;
		line-height: 50upx;
		font-size: larger;
		border-radius: 50%;
		display: flex;
		align-items: flex-end;
		justify-content: space-around;
		background-color: aqua;
		color: #ffffff;
	}
	.dish-choose{
		width: 100upx;
		height: 50upx;
		line-height: 50upx;
		font-size: larger;
		border-radius: 50upx;
		display: flex;
		align-items: flex-end;
		justify-content: space-around;
		background-color: aqua;
		color: #ffffff;
		font-size: small;
	}
</style>